
<template>
    <div class="app-container assembly-list-page">
        <FilterForm
            label-width="85px"
            :data="filterData"
            ref="FilterForm"
            @search="getList"
        />

        <el-row :gutter="10" class="opr-btn-group mb8">
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                    v-hasPermi="['storage:woodTransferRecord:add']"
                    >新增</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="danger"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                    v-hasPermi="['storage:woodTransferRecord:remove']"
                    >删除</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="success"
                    plain
                    size="mini"
                    @click="handleAudit(1)"
                    v-hasPermi="['storage:woodTransferRecord:editAuditState']"
                    >审核</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="success"
                    plain
                    size="mini"
                    @click="handleAudit(0)"
                    v-hasPermi="['storage:woodTransferRecord:editAuditState']"
                    >反审核</el-button
                >
            </el-col>
        </el-row>

        <Table
            :api="$Api.storage.transfer.list"
            :params="queryParams"
            :selection="true"
            height="65vh"
            ref="TableList"
            @select="selectionChange"
            @dbClick="dbclick"
        >
            <el-table-column label="单据日期" prop="receiptsTime" width="120" />
            <el-table-column label="单据编号" prop="transferId" width="160" />
            <el-table-column label="件数" prop="pieceCount" width="120" />
            <el-table-column label="方数" prop="inCount" width="120" />
            <el-table-column label="调出仓库" width="120">
                <template slot-scope="scope">
                    <span v-if="scope.row.outWarehouse">{{
                        JSON.parse(scope.row.outWarehouse).join()
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="调入仓库" prop="" width="160">
                <template slot-scope="scope">
                    <span v-if="scope.row.inWarehouse">{{
                        JSON.parse(scope.row.inWarehouse).join()
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="制单人" prop="createBy" width="120" />
            <el-table-column label="审核人" width="120">
                <template slot-scope="scope">
                    <span>{{
                        scope.row.auditStatus == 0 ? "" : scope.row.auditor
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="备注" />
        </Table>
    </div>
</template>

<script>
export default {
    data: () => {
        return {
            ids: [],
            table: {
                data: [],
                loading: false,
            },
            queryParams: {},
            showSearch: true,
            exportLoading: false,
            filterData: [
                {
                    label: "单据日期",
                    type: "period_date",
                    st: "beginReceiptsTime",
                    end: "endReceiptsTime",
                    scale: 2,
                },
                { label: "单据编号", name: "transferId" },
                {
                    label: "审核状态",
                    name: "auditStatus",
                    type: "select",
                    select: {
                        option: [
                            {
                                value: "1",
                                label: "已审核",
                            },
                            {
                                value: "0",
                                label: "未审核",
                            },
                        ],
                        selectLabel: "label",
                        selectValue: "value",
                    },
                },
            ],
            multiple: true,
        };
    },
    mounted() {},
    created() {},
    methods: {
        dbclick(row) {
            const {transferId} = row;
            let path = `/transfer/detail/${transferId}`;
            this.$router.push({
                path,
            });
        },
        getList(params) {
            this.$refs.TableList.getData(params);
        },
        selectionChange(selection) {
            console.log(selection);
            this.ids = selection.map((item) => item.transferId);
            this.single = selection.length !== 1;
            this.multiple = !selection.length;
        },
        handleAdd() {
            this.$router.push({
                path: "/depot/receipt/transfer",
            });
        },
        handleDelete() {
            let { ids } = this;
            this.$confirm(
                '是否确认删除采购订单信息编号为"' + ids.join() + '"的数据项?',
                "警告",
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            ).then(() => {
                this.$Api.storage.transfer.del(ids.join()).then((res) => {
                    this.msgSuccess(res.msg);
                    this.getList();
                });
            });
        },
        handleAudit(audit) {
            let { ids, loading } = this;
            let { FilterForm, TableList } = this.$refs;

            if (TableList.table.loading) return;

            if (!ids.length) {
                this.$message.error("请至少选择一条数据");
                return false;
            }

            this.$Api.storage.transfer
                .audit({
                    transferIdArray: ids,
                    auditStatus: audit,
                })
                .then((res) => {
                    this.$message.success("操作成功");
                    FilterForm.search();
                })
                .catch(() => {
                    FilterForm.search();
                });
        },
    },
};
</script>

<style lang="scss" scoped>
.assembly-list-page {
}
</style>